<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="场站名称" prop="stationName">
        <el-input
          v-model="queryParams.stationName"
          placeholder="请输入场站名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  label="所属区域" prop="areaCode">
        <el-select v-model="queryParams.areaCode"  placeholder="请选择">
          <el-option
            v-for="item in jurisdictionUnitData"
            :key="item.areaCode"
            :label="item.areaName"
            :value="item.areaCode"
          ></el-option>
        </el-select>

      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table  v-loading="loading"  :data="stationList">
      <el-table-column label="场站名称" align="left" prop="stationName" />
      <el-table-column label="进场监控" align="center" prop="enterMonitor" >
        <template scope="scope">
          <span v-if="scope.row.enterMonitor==='1'" style="color: green">在线</span>
          <span v-else-if="scope.row.enterMonitor==='0'" style="color: dimgrey">离线</span>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="出场监控" align="center" prop="leaveMonitor">
        <template scope="scope">
          <span v-if="scope.row.leaveMonitor==='1'" style="color: green">在线</span>
          <span v-else-if="scope.row.leaveMonitor==='0'" style="color: dimgrey">离线</span>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="地磅称重监控" align="center" prop="weightMonitor">
        <template scope="scope">
          <span v-if="scope.row.weightMonitor==='1'" style="color: green">在线</span>
          <span v-else-if="scope.row.weightMonitor==='0'" style="color: dimgrey">离线</span>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="所属区域" align="center" prop="jurisdictionUnit" :formatter="converJurisdictionUnit"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { stationCamera } from "@/api/weight/camera";
  import { getAreaListByUserId } from "@/api/weight/station";

  export default {
    name: "camerawarn",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 场站信息表格数据
        stations: [],
        stationList: [],
        // 管辖单位
        jurisdictionUnitData: [],
        total:undefined,
        getRowKeys (row) {
          return row.id
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          stationName: undefined,
          areaCode: undefined,
        },
      };
    },
    created() {
      this.getList();
      getAreaListByUserId().then(response =>{
        this.jurisdictionUnitData=response.data;
      });
    },
    methods: {
      /** 查询场站信息列表 */
      getList() {
        this.loading = true;
        stationCamera(this.queryParams).then(response => {
          this.stationList = response.rows;
          this.total = response.total;
          this.loading = false;
          // this.stations = [];
          // this.stationList.forEach((item, i) => {
          //   const station = {"id":item.id,"stationName":item.stationName,"isShow":"0",children: item.cameraList};
          //   this.stations.push(station);
          // })

        });
      },
      // 折叠面板每次只能展开一行
      expandSelect (row, expanded) {
        if (expanded) {
          this.expands = []
          if (row) {
            this.expands.push(row.id)
            console.log(this.expands)
          }
        } else {
          this.expands = []
          console.log(this.expands)
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 所属区域转换
      converJurisdictionUnit(row,column){
        let areaName = '';
        this.jurisdictionUnitData.forEach(function (_val,index) {
          if(row.jurisdictionUnit==_val.areaCode){
            areaName = _val.areaName;
            return true;
          }
        });
        return areaName;
      },
    }
  };
</script>

